import { EEventTable } from "../const/BaseDefine";
import { EventMgr } from "../event/EventMgr";
import { IData } from "./IData";

/**
 * 生命数据
 */
export class LiveData implements IData {
    name: string = "LiveData";

    constructor(name: string) {
        this.name = name;
    }

    onChanged(propertyKey: string, oldValue: any, newValue: any): void {
        const dataName = this.name;
        EventMgr.getInstance().emit(EEventTable.DATA_CHANGED, {
            name: `${dataName}.${propertyKey}`,
            body: {
                old: oldValue,
                new: newValue,
            },
        });
    }
}
